import yaml

with open("environment.yaml") as file_handle:
    environment_data = yaml.safe_load(file_handle)

with open("requirements.txt", "w") as file_handle:
    for dependency in environment_data["dependencies"]:
  
        if isinstance(dependency, str):
            arrs = dependency.split("=")
            if len(arrs) >= 2:
                package_name = arrs[0]
                package_version = arrs[1]
            file_handle.write("{}=={}\n".format(package_name, package_version))
        elif dependency['pip'] != None:
            for item in dependency['pip']:
                file_handle.write(item + '\n')